<?php
class ComsenzUserDao
{
	public function __construct()
	{
		$this->_tgUcUser = Db::newDbTable("uc_user");
		$this->_tgDzUser = Db::newDbTable("dz_user");
		$this->_tgDzSession = Db::newDbTable("dz_session");
		$this->_tgDzSetting = Db::newDbTable("dz_setting");
		$this->_tgUchUser = Db::newDbTable("uch_user");
		$this->_tgUchSpace = Db::newDbTable("uch_space");
	}
	
	public function insertUsers($user)
	{
		$now = time();
		$ucUser = array_merge($user, array(
			"myid" => "",
			"myidkey" => "",
			"regip" => $user["signup_ip"],
			"regdate" => $now,
			"lastloginip" => 0,
			"lastlogintime" => 0,
			"salt" => $user["password_mask"],
			"secques" => ""	
		));
		$dzUser = array_merge($ucUser, array(
			"groupid" => 10,
			"timeoffset" => 9999,
			"pmsound" => 1,
			"showemail" => 1,
			"newsletter" => 1,
			"lastvisit" => $now,
			"lastactivity" => $now,
		));
		$uchSpace = array_merge($ucUser, array(
			"groupid" => 5,
			"name" => "",
			"domain" => "",
			"timeoffset" => 9999,
			"pmsound" => 1,
			"showemail" => 1,
			"newsletter" => 1,
			"dateline" => $now,
			"lastlogin" => $now,
		));
		$this->_tgUcUser->insert($ucUser);
		$this->_tgDzUser->insert($dzUser);
		$this->_tgUchUser->insert($ucUser);
		$this->_tgUchSpace->insert($uchSpace);
	}
	
	public function updateUsers($user)
	{
		$this->_tgUcUser->update($user["id"], $user);
	}
	
	public function getDzSetting()
	{
		$setting = array();
		foreach ($this->_tgDzSetting->fetchRows() as $row)
		{
			$setting[$row["variable"]] = $row["value"];
		}
		return $setting;
	}
	
	public function getDzUser($userId)
	{
		return $this->_tgDzUser->fetch($userId);
	}
	
	public function getUchUser($userId)
	{
		return $this->_tgUchUser->fetch($userId);
	}
}